<?php
/**
 * Created by PhpStorm.
 * User: Ysll <754060604@qq.com>
 * Date: 2017/10/9
 * Time: 11:14
 */

namespace Admin\Model;


use Common\Common\Pagination;

class Product extends Model
{
    protected $tableName = 'products';

    protected static $mod;

    /**
     * 获取实例
     *
     * @return \Think\Model
     */
    public static function getInstance()
    {
        if (static::$mod === null) {
            static::$mod = new static();
        }
        return static::$mod;
    }

    /**
     * 插入数据
     *
     * @param array $data
     * @return mixed
     */
    public static function insert(array $data)
    {
        return self::getInstance()->add($data);
    }

    /**
     * 用产品分类获取产品数据和分页信息
     *
     * @param int $page
     * @param int $category_id
     * @param int $limit
     * @return Pagination
     */
    public static function findByCategoryIdToPagination($page, $category_id, $limit = 12)
    {
        return Pagination::make($page, $limit, self::getInstance(), 'product_categories_id = ' . $category_id);
    }
}